<template>
  <div>

    <el-form ref="editForm" :model="formFileds">
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input v-model="formFileds.text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="search()">查询
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="open()">增加
            </el-button>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <!--表格内容-->
    <el-table ref="auctionList" :data="tableData" style="width: 100%; margin-bottom: 5px;" border stripe highlight-current-row
      :default-sort="{prop: 'date', order: 'descending'}"
      :header-cell-style="{textAlign:'center'}" :cell-style="{textAlign:'center'}">
      <el-table-column property="pmhmc" label="拍卖会名称" width="100">
      </el-table-column>
      <el-table-column property="pmhlx" label="拍卖会类型" width="100">
      </el-table-column>
      <el-table-column property="fbzt" label="发布状态">
      </el-table-column>
      <el-table-column property="pmhzt" label="拍卖会状态" width="100">
      </el-table-column>
      <el-table-column property="kpsj" label="开拍时间" width="200">
        <!-- <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 5px">{{scope.row.kpsj}}</span>
        </template> -->
      </el-table-column>
      <el-table-column property="sqzb" label="是否申请直播" width="150">
      </el-table-column>
      <el-table-column property="pmfs" label="拍卖方式">
      </el-table-column>
      <el-table-column property="bmjzsj" label="报名截止时间" width="200">
      </el-table-column>
      <el-table-column property="qcpbm" label="全场拍报名" width="100">
      </el-table-column>
      <el-table-column property="pmqy" label="拍卖企业">
      </el-table-column>
      <el-table-column property="lxfs" label="联系方式">
      </el-table-column>

      <el-table-column property="notice" label="所属公告">
        <el-link @click="noticeDialog()" style="color:#409EFF; " :underline="false">沈阳拍卖</el-link>
      </el-table-column>

      <el-table-column label="标的">
        <el-link @click="objectDialog()" style="color:#409EFF" :underline="false">查看</el-link>
      </el-table-column>
      <el-table-column label="操作" width="150px" fixed="right">
        <template slot-scope="scope">
          <el-dropdown @command="handleCommand" v-if="scope.row.fbzt == '待提交'">
            <el-button type="primary">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="beforeHandleCommand('goUrl',scope.row)">预览</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('rowEdit',scope.row)">编辑</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('rowDel',scope.row)">删除</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('up',scope.row)">上架</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button type="success" size="mini" @click="goUrl('')">预览</el-button>
          <el-button type="primary" size="mini"
            @click="rowEdit(scope.row)">编辑</el-button>
          <el-button type="danger" size="mini"
            @click="rowDel(scope.row, $event);">删除</el-button> -->
            <el-button v-else type="danger" @click="down(scope.row)">下架</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size=this.pageSize :total=this.total :current-page="currentPage" 
    layout="total, sizes, prev, pager, next, jumper" @current-change="getCurrentPage" @size-change="getSize">
    </el-pagination>

    <!-- 增加-弹出层 -->
    <AuctionAdd ref="addRef" v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @dialogClose="dialogClose" @getList="getList">
    </AuctionAdd>
    <AuctionEdit ref="editRef" v-if="isShowEditDialog" :isShowEditDialog="isShowEditDialog" @getList="getList"
    @dialogClose="dialogClose" :rowData="rowData" ></AuctionEdit>
    <Notice v-if="isShowNoticeDialog" :isShowNoticeDialog="isShowNoticeDialog" @dialogClose="dialogClose">
    </Notice>
    <Object v-if="isShowObjectDialog" :isShowObjectDialog="isShowObjectDialog" @dialogClose="dialogClose">
    </Object>
  </div>
</template>
    
<script>
import AuctionAdd from "../auctionManage/auctionAdd.vue";
import AuctionEdit from "../auctionManage/auctionEdit.vue";
import Notice from "./notice.vue";
import Object from "./object.vue";
import { getAll,getDataBy,delData,editData,submit,shelves } from '@/api/auctionManage/auctionManage';
export default {
  name: "auctionManage",
  components: {
    AuctionAdd,
    AuctionEdit,
    Notice,
    Object
  },
  data () {
    return {
      pageSize: 10,
      total: 0,
      currentPage: 1,
      param: '',
      formFileds: {
        text: '',
        param: ''
      },
      tableData: [
        {
          wthtmc: '',//委托合同名称
          pmhbh: '',//拍卖会编号
          pmhmc: '',//拍卖会名称
          pmhlx: 1,//拍卖会类型
          fbzt: 1,//发布状态
          pmhzt: 1,//拍卖会状态
          kpsj: '',//开拍时间
          pmsbh: '',//拍卖师编号
          sqzb: 1,//申请直播
          pmfs: 1,//拍卖方式
          bmjzsj: '',//报名截止时间
          qcpbm: 1,//全场拍报名
          bmtjcl: 1,//报名是否提交材料
          fm: '',//封面
          scclmc: '',//上传材料名称
          remark: '',
          wthtbh: '',//委托合同编号
          zbjtldz: '',//直播间推流地址
          pmqy: '',//拍卖企业
          lxfs: '',//联系方式
          deleteflag: false

        }
      ],
      isShowEditDialog: false,
      isShowAddDialog: false,
      isShowNoticeDialog: false,
      isShowObjectDialog: false,
      rowData: {}
    }
  },
  methods: {
    noticeDialog(){
      this.isShowNoticeDialog = true;
    },
    objectDialog(){
      this.isShowObjectDialog = true;
    },

    dialogClose () {
      this.isShowEditDialog = false;
      this.isShowAddDialog = false;
      this.isShowNoticeDialog = false;
      this.isShowObjectDialog = false;
      this.getList();
    },
    formatTime(time){
            var dateee = new Date(time).toJSON();
            return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
        },
    rowEdit (row) {
        if(row.sqzb == '是'){
          row.sqzb = 'true';
        }
        else{
          row.sqzb = 'false';
        }
        if(row.qcpbm == '是'){
          row.qcpbm = 'true';
        }
        else{
          row.qcpbm = 'false';
        }
      // //当前选中行
      this.rowData = row;
     this.isShowEditDialog = true;
      //this.$refs.editRef.rowEdit(command.row)
    },
    goUrl (url) {
      this.$message.warning('该功能正在开发');
      return ;
      window.open(url, "_blank")
    },
    rowDel (row) {
      // 让当前删除按钮失焦
      // event.target.blur();
      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        delData(row.id).then((res) => {
          if(res){
            // console.log(res.msg);
            this.tableData.splice(row.id, 1);
            this.$message.success('删除成功');
            this.getList();
          }
        })
        
      });
    },

    //打开增加拍卖项目窗口
    open () {
      this.isShowAddDialog = true;
    },
    formatData(tableData){
      for(let item in tableData){
        if(tableData[item].sqzb == true){
          tableData[item].sqzb = '是';
        }
        else{
          tableData[item].sqzb = '否';
        }
        if(tableData[item].qcpbm == true){
          tableData[item].qcpbm = '是';
        }
        else{
          tableData[item].qcpbm = '否';
        }
      }
      return tableData;
    },
    getCurrentPage(currentPage){
      // console.log(currentPage);
      this.currentPage = currentPage;
      this.getList();
    },
    getSize(pageSize){
      // console.log(pageSize);
      this.pageSize = pageSize;
      this.getList();
    },
    getList(){
      this.param = 'pageno=' + this.currentPage + '&countonepage=' + this.pageSize;
      getAll(this.param).then((res) => {
        if(res){
          // console.log(res);
          this.total = res.data.total;
          this.tableData = res.data.list;
          this.tableData = this.formatData(this.tableData);
        }
      })
    },
    search(){
      if(!this.formFileds.text){
        this.getList();
        return ;
      }
      this.formFileds.param = 'input=' + this.formFileds.text + '&pageno='+this.currentPage + '&countonepage=' + this.pageSize;
      getDataBy(this.formFileds.param).then((res) => {
        if(res){
          // console.log(res);
          this.total = res.data.total;
          this.tableData = res.data.list;
          this.tableData = this.formatData(this.tableData);
        }
      })
    },
    beforeHandleCommand(command,row){
      return{
        'command': command,
        'row': row
      }
    },
    handleCommand(command){
      if(command.command == 'goUrl'){
        this.goUrl();
      }
      else if(command.command == 'rowEdit'){
        this.rowEdit(command.row);
        console.log(command.row)
       
      }
      else if(command.command == 'rowDel'){
        this.rowDel(command.row);
      }
      else if(command.command == 'up'){
        this.up(command.row);
      }
    },
    // restart(row){
    //   row.deleteflag = false;
    //   row.kpsj = this.formatTime(row.kpsj);
    //   if(row.sqzb == '是'){
    //     row.sqzb = 'true';
    //     }
    //     else{
    //       row.sqzb = 'false';
    //     }
    //     if(row.qcpbm == '是'){
    //       row.qcpbm = 'true';
    //     }
    //     else{
    //       row.qcpbm = 'false';
    //     }
    //   console.log(row);
    //   editData(row).then((res) => {
    //       if(res){
    //           console.log(res);
    //           this.formatData(this.tableData);
    //       }
    //   })

    // }
    up(row){
      let data = 'id=' + row.id;
      submit(data).then((res) => {
        if(res){
          console.log(res);
          this.$message.success('上架成功');
          this.getList();
        }
      })
    },
    down(row){
      let data = 'id=' + row.id;
      shelves(data).then((res) => {
        if(res){
          console.log(res);
          this.$message.success('下架成功');
          this.getList();
        }
      })
    }
  },
  mounted(){
    this.getList();
  }
}
</script>
    
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
    